home *** CD-ROM | disk | FTP | other *** search
- /*
- * $
- * $ FILE : select.c
- * $ VERSION : 1
- * $ REVISION : 7
- * $ DATE : 08-Dec-93 15:05
- * $
- * $ Author : mvk
- * $
- *
- * This is an example for gbselect.library
- *
- * It creates an select Gadget with four items.
- * The item 4 is Activate if the window is opened or
- * resized.
- *
- */
- /*
- Related Files: gbselect.doc, gbselect.h <- Our Scrollbox gadget
- egsintui.doc, egsintui.h <- window stuff
- egsgadbox.doc, egsgadbox.h <- The actual gadbox
- main.c
- */
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <exec/types.h>
- #include <dos/dos.h>
- #include <exec/memory.h>
- #include <proto/dos.h>
- #include <proto/exec.h>
- #include <egs/egs.h>
- #include <egs/egsintui.h>
- #include <egs/egsgadbox.h>
- #include <egs/egb/gbselect.h>
- #include <egs/proto/all.h>
-
- /*
- ** Protos
- */
- EI_WindowPtr CreateSelectWindow (EI_WindowPtr win);
- APTR My_FindGadget(EB_GadContext GadCon,WORD ID);
- void Clean_Exit (void);
-
- struct Library *EGSIntuiBase=NULL; // EGSIntuition
- struct Library *EGBSelectBase=NULL; // SelectBox
- struct Library *EGBBase=NULL; // gadbox
-
- EB_GadContext GadCon;
- EI_WindowPtr window;
- EB_StrArray elems={"Text 0","Text 1","Text 2","Text 3",NULL};
-
-
- void main (void) {
- EI_EIntuiMsgPtr msg;
- int class;
- struct EI_Gadget *iaddress;
-
- if (!(EGSIntuiBase = OpenLibrary ("egsintui.library",0))) {
- printf ("Unable open egsintui.library.\n");
- Clean_Exit ();
- }
- if (!(EGBSelectBase = OpenLibrary ("egb/gbselect.library",0))) {
- printf ("Unable open gbmenuselect.library.\n");
- Clean_Exit ();
- }
- if (!(EGBBase = OpenLibrary ("egsgadbox.library",0))) {
- printf ("Unable open egsgadbox.library.\n");
- Clean_Exit ();
- }
-
- if (!(window = CreateSelectWindow (NULL))) {
- printf ("Unable to open Window.\n");
- Clean_Exit ();
- }
-
- for (;;) { // Forever
-
- Wait (1<<window->UserPort->mp_SigBit); // wait for our signals
-
- while ( (msg=(struct EI_EIntuiMsg *) GetMsg (window->UserPort)) != NULL) {
-
- class = msg->Class;
- iaddress = (struct EI_Gadget *)msg->IAddress;
-
-
- switch (class) {
-
- case EI_iCLOSEWINDOW:
- ReplyMsg ( (struct Message *)msg);
- Clean_Exit ();
- break;
- // User has begun to resize window
- case EI_iSIZEVERIFY:
- EI_LockIntuition ();
- EI_RemoveGList (window,GadCon->First, GadCon->Num);
- EB_DeleteGadContext (GadCon);
- EI_UnlockIntuition ();
- ReplyMsg ( (struct Message *)msg);
- break;
-
- case EI_iNEWSIZE:
-
- EI_LockIntuition ();
- window = CreateSelectWindow (window);
- EI_AddGList ( window,GadCon->First,GadCon->Num );
- EI_UnlockIntuition ();
- ReplyMsg ( (struct Message *)msg);
- break;
-
- case EI_iGADGETUP:
- printf("Gadget no=%d \n",((EGB_SelectGadgetPtr)iaddress)->Sel);
-
- ReplyMsg ( (struct Message *)msg);
- break;
-
- }
- }
- }
- }
-
- /*
- **
- ** CreateSelectGadgets
- **
- */
- EI_WindowPtr CreateSelectWindow (EI_WindowPtr win)
- {
-
- EB_GadBoxPtr root;
-
- GadCon = EB_CreateGadContext (NULL,NULL,-1,-1);
-
- root = EB_CreateHorizBox (GadCon);
- EB_AddLastSon (root,EB_CreateHorizFill (GadCon,EB_FILL_ALL,0));
-
- EB_AddLastSon (root,EGB_CreateTextSelectGadget(GadCon,0x300,&elems));
-
- EB_AddLastSon (root,EB_CreateHorizFill (GadCon,EB_FILL_ALL,0));
-
- root = EB_CreateMasterWindow (GadCon,win,root);
-
- if (EB_ProcessGadBoxes (GadCon,root))
- {
-
- if (win==NULL) {
- GadCon->NewWin->IDCMPFlags |= EI_iCLOSEWINDOW | EI_iSIZEVERIFY |
- EI_iNEWSIZE | EI_iGADGETUP |
- EI_iGADGETDOWN;
-
- GadCon->NewWin->Bordef.SysGadgets |= (EI_WINDOWCLOSE)|(EI_WINDOWSIZE);
-
- /*
- **
- ** EI_GIMMEZEROZERO is required for a sizeable GadBox
- **
- */
-
- GadCon->NewWin->Flags |= (EI_SIZEBBOTTOM | EI_GIMMEZEROZERO);
-
- win=EI_OpenWindow (GadCon->NewWin);
-
- }
-
- EGB_ModifySelectGadget(win,My_FindGadget(GadCon,0x300),3);
-
- return (win);
-
- }else
- return NULL;
- }
-
-
- /*
- **
- ** This function searched for Subgadget in a MasterGadget,
- ** because all Gadgets are in a MasterWindow.
- **
- */
- APTR My_FindGadget(EB_GadContext GadCon,WORD ID)
- {
- /*
- ** MasterGadPtr because the window is create with
- ** EB_CreateMasterWindow function
- */
- return( EB_FindGadget(
- ((EI_MasterGadPtr)GadCon->First)->FirstSon,
- ((EI_MasterGadPtr)GadCon->First)->NumSons,ID));
- }
-
- void Clean_Exit (void) {
-
- if (window)
- EI_CloseWindow (window);
- if (GadCon)
- EB_DeleteGadContext (GadCon);
- if (EGBBase)
- CloseLibrary (EGBBase);
- if (EGBSelectBase)
- CloseLibrary (EGBSelectBase);
- if (EGSIntuiBase)
- CloseLibrary (EGSIntuiBase);
-
- exit (0);
- }
-